﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Electure.DAL;

namespace Electure
{
    public partial class search : System.Web.UI.Page
    {
        string Query
        {
            get
            {
                return Request.QueryString["q"];
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            tbSearch.Value = Query;
            using (var repNews = RepositoryFactory.GetNewsRepository())
            {
                var searchResult = repNews.Search(Query);
                newsListControl.Content = searchResult;
                newsListControl.Visible = searchResult.Count > 0;
                lbNewsNotFound.Visible = searchResult.Count == 0;
                lbNewsCount.Text = searchResult.Count > 0 ? searchResult.Count.ToString() : "0 - результатів";
                if (searchResult.Count == 0)
                {
                    collapseNews.Attributes.Add("class", "panel-collapse collapse");
                }
            }
            using (var repPubl = RepositoryFactory.GetPublicationRepository())
            {
                var searchResult = repPubl.Search(Query);
                publicationsList.Content = searchResult;
                publicationsList.Visible = searchResult.Count > 0;
                lbPublNotFound.Visible = searchResult.Count == 0;
                lbPublCount.Text = searchResult.Count > 0 ? searchResult.Count.ToString() : "0 - результатів";
                if (searchResult.Count == 0)
                {
                    collapsePubl.Attributes.Add("class", "panel-collapse collapse");
                }
            }
        }
    }
}